package QueuePackage;

/**
 * @author Lzm
 * @version 1.0
 */
public class CircleQueueTest {
}

/*分析环形队列*/
class CircleQueue{
  private int rear;
  private int[] arr;
  private int MaxSize;
  private int front;
  public CircleQueue(int MaxSize){
    this.MaxSize = MaxSize;
    this.arr = new int[MaxSize];
    this.front = 0;
    this.rear = 0;
  }
  /*判空*/
  public boolean isEmpty(){
    return rear == front;
  }

  /*判满*/
  public boolean isFull(){
    return (rear + 1) % MaxSize == front;
  }

  /*求队列长度*/
  public int length(){
    return (rear + MaxSize - front) % MaxSize;
  }

  /*添加数据*/
  public void add(int number){
    if (isFull()){
      return;
    }
    arr[rear++] = number;
  }

  /*取出数据*/
  public int get(){
    if (isEmpty()){
      System.out.println("队列为空");
      return -1;
    }
    return arr[front--];
  }
}
